﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.ServiceModel.Channels;
using ch02.service.contract;

namespace ch02.client
{
    public partial class Index : System.Web.UI.Page
    {
        protected double result;
        protected double x;
        protected double y;
        protected void Page_Load(object sender, EventArgs e)
        {
            Uri uri = new Uri("http://127.0.0.1:8888/myservices");
            //AddressHeader header = AddressHeader.CreateAddressHeader("Licensed User", "http://www.wcf-programming.com", "administrator");
            EndpointAddress address = new EndpointAddress(uri);
            Binding binding = new WSHttpBinding();
            ContractDescription contract = ContractDescription.GetContract(typeof(ICalculator));
            ServiceEndpoint endpoint = new ServiceEndpoint(contract, binding, null);

            using (ChannelFactory<ICalculator> channel_factory = new ChannelFactory<ICalculator>(endpoint))
            {
                AddressHeader header = AddressHeader.CreateAddressHeader("Licensed User", "http://www.wcf-programming.com", "administrator");
                ICalculator proxy = channel_factory.CreateChannel();
                x = 23.43;
                y = 234.3;
                result = proxy.Add(x, y);
                using (OperationContextScope operationContextScope = new OperationContextScope(proxy as IContextChannel))
                {
                    OperationContext.Current.OutgoingMessageHeaders.Add(header.ToMessageHeader());

                }

            }
        }
    }
}